package com.olympia.myapp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.olympia.myapp.R;
import com.olympia.myapp.entity.Player;

public class PlayerAdapter extends ArrayAdapter<Player> {
	private LayoutInflater mInflater;

	public PlayerAdapter(Context context) {
		super(context, R.id.player_item_name);
		this.mInflater = LayoutInflater.from(context);
	}

	public class ViewHolder {
		TextView txtId;
		TextView txtName;
	}

	@Override
	public View getView(final int position, View view, ViewGroup parent) {
		final ViewHolder holder;
		Player entry = (Player) getItem(position);
		if (view == null) {
			holder = new ViewHolder();
			view = mInflater.inflate(R.layout.player_item, null);

			holder.txtId = (TextView) view.findViewById(R.id.player_item_id);
			holder.txtName = (TextView) view
					.findViewById(R.id.player_item_name);

			view.setTag(holder);
		} else {
			holder = (ViewHolder) view.getTag();
		}

		if (entry != null) {
			holder.txtId.setText(entry.id + ".");
			holder.txtName.setText(entry.name);
		}

		return view;
	}
}
